<template>
  <div>
    <br />
    <a-card title="Elastic Search">
      <a-row>
        <a-col span="2">Elastic Search</a-col>
        <a-col span="22">
          <a-button
            class="btn"
            type="primary"
            size="small"
            @click="btnClick(false)"
          >
            分词器
          </a-button>
        </a-col>
      </a-row>
    </a-card>
    <input-modal
      ref="InputModal"
      title="分词器"
      :auto-close="false"
      placeholder="请输入文本"
      width="1000px"
      @success="inputSuccess"
    >
      <div v-if="dataArr.length > 0">
        <br />
        <a-tag v-for="item in dataArr" :key="item.start_offset" color="pink">
          {{ item.token }}
        </a-tag>
      </div>
    </input-modal>
  </div>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import InputModal, { InputModalComType } from '@/components/global/modal/input'
import { Api } from '@/config/api'

@Component({
  name: 'ComWebToolPdf',
  components: {
    InputModal
  }
})
export default class ComWebToolPdf extends Vue {
  pdfType = false

  dataArr: Array<any> = []

  btnClick (type: boolean) {
    this.dataArr = []
    this.pdfType = type;
    (this.$refs.InputModal as InputModalComType).show()
  }

  inputSuccess (value: string) {
    this.$wAxios.$post(Api.elasticsearch.analyze, {
      analyzer: 'simple',
      text: value
    }).then((dataArr) => {
      this.dataArr = dataArr
    })
  }
}
</script>

<style scoped></style>
